<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/includes/common-import.jsp"%>
<!DOCTYPE HTML>
<HTML>
<HEAD>
<META content="IE=10.0000" http-equiv="X-UA-Compatible">

<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<TITLE>${systemName }</TITLE>
<link href="${resPath}main/css/style.css" rel="stylesheet" type="text/css" />
<script language="javascript" src="${resPath}main/js/label.js"></script>
<script type="text/javascript" src="${resPath}main/js/jquery-1.8.3.min.js"></script>  
<script src="${resPath}media/js/uniteTable.js"></script>  
<script type="text/javascript">
		window.onload=function()
		{
			if(document.getElementById("form1:data") != null){
				uniteTable(document.getElementById("form1:data"),1);
			}
		}
	   function save(){
		   if(sort()){
			   var form = document.getElementById("searchForm");
			   form.action = "${basePath }teacherExamResult/saveDeatil";
			   form.submit();
		   }
	   }
	   function sort(){
			var obj1 = getByNameStartAndEnd("teacherExamResults", "userScore");
			var obj2 = getByNameStartAndEnd("teacherExamResults", "score");
	    	for(var i=0; i<obj1.length; i++) {
	    		if(!isEmptyAnswer(obj1[i],"第"+(i+1)+"的分数不能为空")){
					return false;
				} if(isNaN(obj1[i].value)){
					alert("第"+(i+1)+"的分数不是数字");
					obj1[i].focus();
					obj1[i].select();
					return false;
				} 
	    		else{
					var score = obj2[i].value;
					var userScore = obj1[i].value;
				 	if(parseInt(userScore)>parseInt(score)){
						alert("第"+(i+1)+"的评分数不能大于总分数");
						obj1[i].focus();
						obj1[i].select();
						return false;
					}
				}
	    	}
	    	return true;
		}
		function getByNameStartAndEnd(start,end) {
			var obj = document.getElementsByTagName("input");
			var arrayObj = new Array(); 
			if(obj == null) {
				return arrayObj;
			}
			for(var i=0; i<obj.length; i++) {
				var name_length = obj[i].name.length;
				var str = obj[i].name.slice(0, start.length);
				var str1 = "";
				if(name_length > end.length) {
					str1 = obj[i].name.slice(name_length - end.length, name_length);
				}
				if(str == start && str1 == end ){
					arrayObj.push(obj[i]);
				}
			}
			return arrayObj;
		}
		/*
		 * 描述： 校验对象非空
		 * param: obj 页面元素input 类型对象
			 * param: message 警告消息
		 * 操作记录：
		 * 操作人 操作时间 注释
		 * --------------------------
		 * 邵文泽  创建
		 */	
		function isEmptyAnswer(obj, message) {
			var eleValue = obj.value;
			if (eleValue == "" || eleValue.length == 0) {
				alert(message);
				obj.focus();
				obj.select();
				return false;
			}
			return true;
		}
	</script>
<META name="GENERATOR" content="MSHTML 11.00.9600.17041">
</HEAD>
<%@ include file="/WEB-INF/includes/indexHeader.jsp"%>
<DIV id="min_box" style="margin-top: 10px;">
<form id="searchForm" class="form-horizontal" method="post" style="margin-left: 200px;margin-top: 20px;margin-bottom: 30px;">
	
	<div class="portlet">
		<div class="portlet-title">
			<div class="input-prepend input-append" style="color: white;">
	 			        教师名称: <c:out value="${teacherName}"></c:out>
				       考核期间: <c:out value="${examDateName}"></c:out>
					<button type="button" class="ts_log_btn_small" onclick="save();">保存</button> 
				</div>
			</div>
		</div>
		<br />
		<table id="form1:data" style="border: 2px solid rgb(53, 153, 153); width: 80%; color: black; border-collapse: collapse; background-color: white;" border="2" rules="cols" cellspacing="1" cellpadding="3">
		<thead>
			<tr style="color: white; font-weight: bold; background-color: rgb(46, 65, 120);">
					<th>考核类别</th> 
					<th>考核项目</th> 
					<th>内容规则</th> 
					<th>分值</th> 
					<th>评价分数</th> 
			</tr>
		</thead>
		<tbody>
			<c:forEach items="${teacherExamSetting.teacherExamResults}" var="list" varStatus="status">
											<tr class="odd gradeX" >
											<input type="hidden" name="teacherExamResults[${status.index}].id" value="${list.id}" id="teacherExamResultsid[${status.index}]"/>
												<td style="width: 20%">${list.kindName}</td> 
												<td style="width: 30%">${list.examItemName}</td> 
												<td style="width: 30%">
													${list.itemDescription}
												<td style="width: 10%">
													${list.score}
													<input type="hidden" name="teacherExamResults[${status.index}].score" value=${list.score} />  
												</td> 
												<td style="width: 10%">
													<input type="text" id="teacherExamResultsuserScore[${status.index}]" 
													name="teacherExamResults[${status.index}].userScore" maxlength="3"/>
												</td> 
											</tr>
				</c:forEach>
			</tbody>
	</table>
</form>
</DIV>

</BODY>
</HTML>
